package display;

import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

import world.World;
import display.camera.Camera;

/**
 * the most basic display possible, enhancements can definetely be implemented
 * for faster drawing
 * @author jack
 *
 */
public class Display extends JFrame implements Runnable
{
	private static final long serialVersionUID = 1L;
	World w;
	JPanel p;
	Camera c = new Camera(new double[]{0, 0}, new double[]{0, 0}, new int[]{0, 0});
	
	public Display()
	{
		super("");
		p = new JPanel(){
			private static final long serialVersionUID = 1L;
			public void paint(Graphics g)
			{
				w.drawWorld((Graphics2D)g, c);
			}
		};
		p.setIgnoreRepaint(true);
		add(p);
		setSize(900, 600);
		setLocationRelativeTo(null);
		new Thread(this).start();
		setVisible(true);
	}
	public void run()
	{
		long start = System.currentTimeMillis();
		for(;;)
		{
			c.setGameViewDim(new double[]{p.getWidth(), p.getHeight()});
			c.setPhysicalViewDim(new int[]{p.getWidth(), p.getHeight()});
			w.update(System.currentTimeMillis()-start);
			p.repaint();
			try
			{
				Thread.sleep(13);
			}
			catch(InterruptedException e){}
			start = System.currentTimeMillis();
		}
	}
}
